//
//  MenuLayer.m
//  BeatPong
//
//  Created by Gabriel Lumbi on 12-08-20.
//
//

#import "MenuLayer.h"
#import "GameLayer.h"

@implementation MenuLayer

// Helper class method that creates a Scene with the HelloWorldLayer as the only child.
+(CCScene *) scene
{
	CCScene *scene = [CCScene node]; //is an autorelease object
	MenuLayer *layer = [MenuLayer node]; //is an autorelease object
	[scene addChild: layer];
	return scene;
}

#pragma mark -
#pragma mark Life Cycle

-(id) init
{
    if(self = [super init])
    {
        screenSize = self.boundingBox.size;
        
        CCMenuItemFont *playMenuItem = [CCMenuItemFont itemWithString:@"FIGHT"];
        [playMenuItem setFontName:@"Arial"];
        [playMenuItem setColor:ccc3(255, 0, 255)];
        [playMenuItem setFontSize:30];
        [playMenuItem setTarget:self selector:@selector(goToGame)];
        
        CCMenu *menu = [CCMenu menuWithItems:playMenuItem, nil];
        [self addChild:menu];
        
        [self scheduleUpdate];
    }
    return self;
}

-(void) dealloc
{
    [super dealloc];
}

#pragma mark -
#pragma mark Draw

-(void) draw
{
    float sinTime = sinf(currentTime);
    float y = screenSize.height * sinTime*sinTime;
    ccDrawColor4F(1, 0, 1, 1);
    ccDrawLine(ccp(0,y), ccp(screenSize.width,y));
    
    int nbGhostLines = 10;
    for(int i=1;i<=nbGhostLines;i++){
        float sinOldTime = sinf(currentTime - 0.1*i);
        float intensity = (nbGhostLines-i)/(float)nbGhostLines;
        float oldY = screenSize.height * sinOldTime*sinOldTime;
        ccDrawColor4F(intensity, 0, intensity, 1);
        ccDrawLine(ccp(0,oldY), ccp(screenSize.width,oldY));
    }
}


#pragma mark -
#pragma mark Update

-(void) update:(ccTime)delta
{
    currentTime += delta;
}

#pragma mark -
#pragma mark Scene Change

-(void) goToGame{
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[GameLayer scene] withColor:ccc3(225, 0, 225)]];
}

@end